package com.edu.exam.enums.exampaper.review;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 试卷检查任务状态枚举
 *
 * 专门用于试卷检查相关功能的状态管理
 *
 * @author System
 * @version 1.0.0
 */
public enum ExamPaperCheckTaskStatus implements BaseEnum {

    /**
     * 待处理
     */
    PENDING("PENDING", "待处理"),

    /**
     * 进行中
     */
    IN_PROGRESS("IN_PROGRESS", "进行中"),

    /**
     * 已完成
     */
    COMPLETED("COMPLETED", "已完成"),

    /**
     * 已取消
     */
    CANCELLED("CANCELLED", "已取消"),

    /**
     * 失败
     */
    FAILED("FAILED", "失败"),

    /**
     * 暂停
     */
    PAUSED("PAUSED", "暂停"),

    /**
     * 超时
     */
    TIMEOUT("TIMEOUT", "超时"),

    /**
     * 已分配
     */
    ASSIGNED("ASSIGNED", "已分配"),

    /**
     * 已通过
     */
    APPROVED("APPROVED", "已通过"),

    /**
     * 已拒绝
     */
    REJECTED("REJECTED", "已拒绝"),

    /**
     * 已过期
     */
    EXPIRED("EXPIRED", "已过期");

    private final String code;
    private final String description;

    ExamPaperCheckTaskStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static ExamPaperCheckTaskStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Task status code cannot be null or empty");
        }
        for (ExamPaperCheckTaskStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown task status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static ExamPaperCheckTaskStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Task status description cannot be null or empty");
        }
        for (ExamPaperCheckTaskStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown task status description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}